@extends('wechat.layouts.base')
@section("js_files")
    <script src="{{asset('dist/wechat/js/index/build.js')}}"></script>
    <script src="{{asset('dist/wechat/js/share_file.js')}}"></script>
@endsection
@section('content')
		<div class="weui_dialog_alert" style="display: none;">
            <div class="weui-mask"></div>
            <div class="weui-dialog">
                <div class="weui-dialog__hd"><strong class="weui-dialog__title">弹窗标题</strong></div>
                <div class="weui-dialog__bd">弹窗内容，告知当前页面信息等</div>
                <div class="weui-dialog__ft">
                    <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">确定</a>
                </div>
            </div>
        </div>
        <div id="loadingToast" style="display:none;">
            <div class="weui-mask_transparent"></div>
            <div class="weui-toast">
            <i class="weui-loading weui-icon_toast"></i>
            <p class="weui-toast__content">提交信息中</p>
        </div>
            </div>
        <div id="awardpic"><img width="100%" src="{{$prize->prize->attachBo->path}}"></div>
        <div class="weui-cells__title">商家输入兑奖密码</div>
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input class="weui-input" style="text-align: center" type="text" placeholder="在此输入兑换密码"/>
                </div>
            </div>
        </div>
        <div id="submit">
            <a id="rewardbtn" href="javascript:;">确定</a>
        </div>
        <div class="weui-panel weui-panel_access" style="margin-top: 50px">
            <div class="weui-panel__hd">兑奖需知</div>
            <div class="weui-panel__bd">
                <div class="weui-media-box weui-media-box_text">
<!--                    <h4 class="weui-media-box__title">兑奖时间：2017.1.4- 2017.2.28</h4>  -->
                    <p class="weui-media-box__desc">{{$prize->prize->info}}</p>
                </div>
            </div>
        </div>
    @endsection
	@section('js')
	 <script>
            var l_id = {{$prize->id}};
            var token = "{{ csrf_token() }}";
            $.weui = {};
            $.weui.alert = function(options){
                options = $.extend({title: '警告', text: '警告内容'}, options);
                var $alert = $('.weui_dialog_alert');
                $alert.find('.weui-dialog__title').text(options.title);
                $alert.find('.weui-dialog__bd').text(options.text);
                $alert.on('touchend click', '.weui-dialog__btn', function(){
                    $alert.hide();
                });
                $alert.show();
            };
            $(function () {
                $('#rewardbtn').on('click',function () {
                    if($('.weui-input').val()== ""){
                        $.weui.alert({text: "请输入兑换密码！"});
                        return
                    }else {
                        $.ajax({
                            type:'POST',
                            url:"{{url('wechat/mine/verify/code')}}",
                            data:{
                                v_code:$('.weui-input').val(),l_id:l_id,_token:token,
                            },
                            beforeSend: function () {
                                // 禁用按钮防止重复提交
                                $('#loadingToast').css('display','block');
                            },
                            success:function (data) {
                                if(data.success == true){
                                        alert(data.msg);
                                    window.location.href="{{url('wechat/mine')}}";
                                }else{
                                    alert(data.msg);
                                    $('.weui-input').val("");
                                }
                                console.log(data);

                                //window.location.href=mine.php;

                            },
                            complete:function(){
                                $('#loadingToast').css('display','none');
                            }
                        });
                    }
                });
            });
        </script>
		@endsection
